home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 016a / 4dtnt.zip / WHATYPE.DOC < prev    next >
Text File  |  1991-11-03  |  1KB  |  45 lines

  1. Yet another evolution of BUMP.  This is a generalization of the validation
  2. subroutine.  It returns (as errorlevel) the lowest number base for which the
  3. input string is valid.  For example, "2739847" would return errorlevel 10
  4. because the "9" in the string means the number base is at least 10.
  5.  
  6. This can be used as a general purpose base n validation routine.  For example,
  7. if you expect hexadecimal, errorlevel must be 16 or less.
  8.  
  9. if "%1" == "" goto help
  10.  
  11.   Setlocal works here because no caller variables are changed.
  12. setlocal
  13.  
  14.   Standardize character case
  15. set $foo=%@upper[%1]
  16.  
  17.   The inevitable base 36 validation string.
  18. set $wstr=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
  19.  
  20.   Initialize the loop counter and return value
  21. set $i=0
  22. set $r=0
  23.  
  24. :valloop
  25.  
  26.   Use the index into wstr for each character as a means of validation.
  27. set $val=%@index[%$wstr,%@substr[%$foo,%$i,1]]
  28.  
  29.   If the character does not exist in wstr, the string is invalid.
  30. if %$val lt 0 quit 99
  31.  
  32.   Keep the maximum value ever found (the highest digit) in the string.
  33. if %$r le %$val set $r=%@eval[%$val+1]
  34.  
  35.   Bump the loop along and test for done.
  36. set $i=%@eval[%$i+1]
  37. if %$i lt %@len[%$foo] goto valloop
  38.  
  39.   Return with the errorlevel set.
  40. quit %$r
  41.  
  42. :help
  43. echo Usage %@name[%0] string
  44. echo Errorlevel = number base (1 - 36) of string or 99 for not valid.
  45. quit 99